package com.share.common.enums;

import lombok.Getter;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

@Getter
public enum ProductCodeEnum {
    JDBT("jdbt", "京东白条"),
    MAYI("mayi", "蚂蚁花呗");


    //主题编码
    public String code;

    //主题名字
    public String name;


    private ProductCodeEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public static ProductCodeEnum toEnum(final String code) {
        for (final ProductCodeEnum tag : ProductCodeEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }

    public static List<String> listCode() {
        List<String> list = new LinkedList<>();
        for (ProductCodeEnum typeEnum : ProductCodeEnum.values()) {
            list.add(typeEnum.code);
        }
        return list;
    }
}
